//
//  HewardSelectPayTyprController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/22.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "HewardSelectPayTyprController.h"

@interface HewardSelectPayTyprController ()
/**支付选择按钮*/
@property (nonatomic,strong)UIButton*selectZFB;
/**微信选择按钮*/
@property (nonatomic,strong)UIButton*selectWX;

@end

@implementation HewardSelectPayTyprController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"支付方式";
    [self createUI];
}
-(void)createUI{
    UIView * bottomView = [self createBottomView];
    
    [self.view addSubview:bottomView];
    
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    
    
    UIView * zfbView = [self createViewTitle:@"zfb_pay" name:@"支付宝支付" selectButton:self.selectZFB];
    
    UIView * lineView = UIView.new;
    lineView.backgroundColor = UIColorFromRGB(0xE7EEE7);

    UIView * wxView = [self createViewTitle:@"wx_pay" name:@"微信支付" selectButton:self.selectWX];

    [self.view addSubview:zfbView];
    [self.view addSubview:lineView];
    [self.view addSubview:wxView];

    [zfbView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(65);
    }];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(0.5);
        make.top.mas_equalTo(zfbView.mas_bottom);
    }];
    [wxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(zfbView);
        make.top.mas_equalTo(lineView.mas_bottom);
        make.height.mas_equalTo(65);

    }];

}

#pragma mark 懒加载
-(UIView *)createViewTitle:(NSString *)imageStr name:(NSString *)nameStr selectButton:(UIButton *)button{
    UIView * view = UIView.new;
    UIImageView * imageView = [[UIImageView alloc]initWithImage:IMAGE_NAMED(imageStr)];
//    imageView.backgroundColor = KGrayColor;
    imageView.layer.cornerRadius = 18;
    
    UILabel * label = UILabel.new;
    label.textColor = UIColorFromRGB(0x273323);
    label.font = PingFangSC_Regular(16);
    label.text = nameStr;
    
    [view addSubview:imageView];
    [view addSubview:label];
    [view addSubview:button];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.centerY.mas_equalTo(0);
        make.width.height.mas_equalTo(36);
    }];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(imageView.mas_right).offset(10);
    }];
    
    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.width.height.mas_equalTo(16);
    }];
    
    
    return view;
}
-(UIButton*)selectZFB{
    if(!_selectZFB){
        _selectZFB=[UIButton buttonWithType:UIButtonTypeCustom];
        [_selectZFB setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
        [_selectZFB setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_selecet") forState:UIControlStateSelected];
        _selectZFB.selected = YES;
        kWeakSelf(weakSelf);
        [_selectZFB addActionHandler:^{
            weakSelf.selectWX.selected=NO;
            weakSelf.selectZFB.selected = YES;
        }];

    }
    return _selectZFB;
}
-(UIButton*)selectWX{
    if(!_selectWX){
        _selectWX=[UIButton buttonWithType:UIButtonTypeCustom];
        [_selectWX setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
        [_selectWX setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_selecet") forState:UIControlStateSelected];
        _selectWX.selected = NO;
        
        kWeakSelf(weakSelf);
        [_selectWX addActionHandler:^{
            weakSelf.selectWX.selected=YES;
            weakSelf.selectZFB.selected = NO;
        }];
        
    }
    return _selectWX;
}

-(UIView *)createBottomView{
    UIView * view = UIView.new;
    
    view.backgroundColor = UIColorFromRGB(0x009966);
    
    UILabel * label = UILabel.new;
    label.textColor = KWhiteColor;
    label.font = PingFangSC_Medium(18);
    label.text = @"去支付";
    
    [view addSubview:label];
    
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}
@end
